'use strict';

var checkRegisterForm = function () {
    // TODO:
    let reg = /^[a-zA-Z0-9]{3,10}$/,
        account = document.getElementById('username'),
        pwd = document.getElementById('password'),
        rePwd = document.getElementById("password-2");

    if (reg.test(account.value)) {
        if (pwd.value.length >= 6 && pwd.value.length <= 20 ) {
            if (rePwd.value === pwd.value) {
                return true
            } else {
                alert('两次密码不一致');
            }
        } else {
            alert('口令长度必须在6-20位之间');
        }
    } else {
        alert('非法的用户名');
    }
    
    return false;
}

// 测试:
;(function () {
    window.testFormHandler = checkRegisterForm;
    var form = document.getElementById('test-register');
    if (form.dispatchEvent) {
        var event = new Event('submit', {
    		bubbles: true,
    		cancelable: true
  		});
        form.dispatchEvent(event);
    } else {
        form.fireEvent('onsubmit');
    }
})();
